{% extends "base.html" %}
{% block header %}角色管理{% endblock %}
{% block content %}
<div class="card shadow-sm rounded p-4 mb-4">
    <div class="d-flex justify-content-between align-items-center mb-3">
        <h4 class="mb-0">角色列表</h4>
        <a href="/add_role/" class="btn btn-success">添加新角色</a>
    </div>
    <div class="table-responsive">
        <table class="table table-bordered align-middle">
            <thead class="table-light">
                <tr>
                    <th>角色名称</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {% for role in page_obj %}
                <tr>
                    <td>{{ role.name }}</td>
                    <td>
                        <a href="/edit_role/{{ role.id }}/" class="btn btn-sm btn-primary">编辑</a>
                    </td>
                </tr>
                {% empty %}
                <tr><td colspan="2" class="text-center">暂无角色信息</td></tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
    <!-- 分页控件 -->
    <nav aria-label="Page navigation">
      <ul class="pagination">
        {% if page_obj.number > 1 %}
          <li class="page-item"><a class="page-link" href="?page=1">首页</a></li>
        {% endif %}
        {% if page_obj.has_previous %}
          <li class="page-item"><a class="page-link" href="?page={{ page_obj.previous_page_number }}">上一页</a></li>
        {% endif %}
        {% for num in page_obj.paginator.page_range %}
          {% if page_obj.number == num %}
            <li class="page-item active"><span class="page-link">{{ num }}</span></li>
          {% else %}
            <li class="page-item"><a class="page-link" href="?page={{ num }}">{{ num }}</a></li>
          {% endif %}
        {% endfor %}
        {% if page_obj.has_next %}
          <li class="page-item"><a class="page-link" href="?page={{ page_obj.next_page_number }}">下一页</a></li>
        {% endif %}
        {% if page_obj.number < page_obj.paginator.num_pages %}
          <li class="page-item"><a class="page-link" href="?page={{ page_obj.paginator.num_pages }}">尾页</a></li>
        {% endif %}
      </ul>
    </nav>
</div>
{% endblock %}
